//Ext.namespace("Project.Draft");

this.Draft = function(){
	var thiz=this;

	var userSelector = null;
	var selectUserId = [];
	var userSelector2 = null;
	var selectUserId2 = [];
	var project_id ='-1';	
	var ps = new ProjectSourceDemo();	
	// 查询条件---begin
	var searchName = new Ext.form.TextField({
		fieldLabel : '客户名称',
		width : 150
	});
	
	var searchArea = new Ext.form.ComboBox( {
		fieldLabel : '所属区域',
		//hiddenName : 'type',
		store: OMS.AREA,
		mode : 'local',
		displayField : 'name',
		triggerAction : 'all',
		editable : false,
		valueField : 'id',
		typeAhead : true,
		width : 150,
		emptyText : '---请选择---',
		selectOnFocus : true
	});
	
	var COMPANYSIZE = new Ext.form.ComboBox( {
		fieldLabel : '公司规模',
		//hiddenName : 'type',
		store: OMS.COMPANYSIZE,
		mode : 'local',
		displayField : 'name',
		triggerAction : 'all',
		editable : false,
		valueField : 'id',
		typeAhead : true,
		width : 150,
		emptyText : '---请选择---',
		selectOnFocus : true
	});
	
	var searchComplateDate = new Ext.form.DateField( {
		fieldLabel : '生成时间',
		format : 'Y-m-d',
		width : 150
	});
	var searchEndDate = new Ext.form.DateField( {
		fieldLabel : '至',
		format : 'Y-m-d',
		width : 150
	});
	
	var btn_search = new Ext.Button({
		text : '查询',
		iconCls: 'icon-search',
		handler: function (){searchCustomer();}
	});
	var customerStore = new Ext.data.JsonStore(
			{
				url : '../customer/searchCustomer.form?status=11&timesnap=' + new Date()
						.getTime(),
				root : 'result',
				fields : [ 'id', 'CustomerName', 'Area',
						'CustomerSize', 'CustomerType', 'CustomerAddress',
						'FirstContact', 'Mobile', 'Leader', 'EmployCount',
						'CompanyPhone', 'MSN', 'Email', 'Fax',
						'ContactLike', 'Birthday', 'SecondContact',
						'SecondMobile', 'PhoneMoney', 'MailMoney', 'NetMoney',
						'SuccessTime', 'Stage', 'VsName',
						'NsManager', 'VsTime', 'VsGood', 'VsBad',
						'CreateTime','CreateBy','LastUpdateTime','LastUpdateBy' ],
				listeners : {
					scope : this,
					beforeload : function(thiz) {
						thiz.baseParams = {
							searchName : searchName.getValue(),
							companysize:COMPANYSIZE.getValue(),
							stage:0,
							searchArea : searchArea.getValue(),
							searchEndDate:searchEndDate.getValue() ? searchEndDate.getValue().format('y-m-d') : '',
							searchComplateDate : searchComplateDate.getValue() ? searchComplateDate.getValue().format('Y-m-d') : ''
							
						};
					}
				}
			});
	
	
	var xg = Ext.grid
	var sm = new xg.CheckboxSelectionModel();
	
	var PublicCustomerGrid = new Ext.grid.GridPanel({
	sm: sm,
	
		width : 930,
		height : 350,
		store : customerStore,
		scope:this,
		listeners : {
			scope : this,
			rowmousedown : function(grid,index,e){
							}
		},
		columns : [
		sm,
		
				   {header:'客户名称',width: 150,sortable: true,dataIndex:'CustomerName'},
		           {header:'所属区域',width: 100, sortable: true,dataIndex:'Area',renderer:function(value){return OMS.AREA[value];}},
		           {header:'项目类型',dataIndex:'CustomerType',renderer:function(value,row){return OMS.CUSTOMERTYPE[value];}},
		           {header:'公司地址',dataIndex:'CustomerAddress'},
		           {header:'联系人姓名',width: 170,dataIndex:'FirstContact'},
		           {header:'联系人电话',dataIndex:'Mobile'}],
       bbar:new Ext.PagingToolbar({
		 pageSize: 5,
         store: customerStore,
         displayInfo: true,
         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
         emptyMsg: "没有记录..."
       })
	});
	
	
	
	
// 在project_main.js 里  items : [ new Draft()<=js名称  .beforeSell  <=  FormPanel 方法]
	this.beforeSell = new Ext.form.FormPanel({
		frame : true,
		width : 950,
		fileUpload: true, 
		labelWidth : 85,
		buttons : [
		           {text:'保存',iconCls: 'icon-accept',scope:this,handler:function(){
					var scope=this;
						Utils.confirm2({
							msg:"是否选择下列数据？",
							  	width:220,
								fn:function(){
									//	alert(label);
										var count=PublicCustomerGrid.getSelectionModel().getSelections();
										var ids="";
										if(count<=0){//这里 的逻辑 按照网格里的数据判断的
											alert("请选择数据");
											return false;
											}
										for(var i=0 ;i<count.length;i++){
											var data = count[i].data['id'];
											ids+=count[i].data['id']+',';
											}
										scope.beforeSell.getForm().submit({
											waitTitle : '系统提示',
											waitMsg : '数据提交中，请稍候...',
											url:'../customer/chooseCustomer.form?timesnap=' + new Date().getTime()+'&ids='+ids,
											method:'post',
											success:function(data){
												Utils.info("操作成功","系统提示");	
												customerStore.load();
												}
									});
							}
						});
		           	}},
		           {text:'重置',iconCls: 'icon-return',scope:this,handler:function(){
		           		this.beforeSell.getForm().reset();}}
		           ],
		           items : [{layout:'column',defaults:{layout:'form'},
		        	   		items:[{columnWidth:0.3,items:[searchName]},
		        	   		       {columnWidth:0.3,items:[searchArea]},
		        	   		       {columnWidth:0.3,items:[COMPANYSIZE]},
		        	   		       {columnWidth:0.3,items:[searchComplateDate]},
		        	   		       {columnWidth:0.3,items:[searchEndDate]},
		        	   		       {columnWidth:0.15,items:[btn_search]}]
		           			},PublicCustomerGrid],
		        listeners: {
		    		render: {fn:function(){ 
						customerStore.load();
						//strackStore.load();
			}}
		}
	});
	
	//Draft.constructor.call
		
	
//	Draft.superclass.constructor.call(this, {
//			listeners: {
//		    		render: {fn:function(){ 
//		    			alert("dddd");
//						customerStore.load();
//			}}
//		}
//		}
//	)

	//检索项目
	var searchCustomer = function(){
		customerStore.reload();
		
	};
	
	
	


}